package com.zhangpengkai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangpengkai.domain.User;
import com.zhangpengkai.mapper.UserMapper;
import com.zhangpengkai.service.UserService;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author 34129
* @description 针对表【user】的数据库操作Service实现
* @createDate 2023-12-31 00:33:28
*/
@Service
public class UserServiceImpl implements UserService{


    private SqlSessionTemplate sqlSessionTemplate;

    @Resource
    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }


    @Override
    public User selectUser(String username) {

        UserMapper mapper = sqlSessionTemplate.getMapper(UserMapper.class);
        User user = mapper.selectUser(username);

        return user;
    }



    public boolean login(User user){
        User user1 = selectUser(user.getUsername());

        if(user1.getUsername()==null){
            System.out.println("账号错误");
        } else if (user1!=null && !user1.getPassword().equals(user.getPassword())){
            System.out.println("密码错误");
        }
        return true;
    }
}




